package com.equipment.fkdcn.controller;


import com.equipment.fkdcn.tool.PeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@RestController
@RequestMapping("/people")
public class PeopleController {

    private static String validationCode;

    @Autowired
    private PeopleService peopleService;
    public void doGet(HttpServletRequest request, HttpServletResponse response)  {
        peopleService.doGet(request,response);

    }

    @RequestMapping("/post")
    @ResponseBody
    public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException{
        peopleService.doPost(request,response);
         HttpSession session = request.getSession();
        validationCode=session.getAttribute("validationCode").toString();
    }


    //匹配验证码
    @PostMapping("/vCode")
    @ResponseBody
    public String eqValidationCode(@RequestParam("str") String str){
        boolean f=true;
        if (!this.validationCode.equals(str)){
            f=false;
        }
        return  "{\"state\":"+f+"}";
    }


}
